package cn.summit.exception;

import lombok.Getter;
import lombok.Setter;
import org.apache.commons.lang3.StringUtils;

import java.util.regex.Matcher;

/**
 * 基础异常类
 *
 * @author zj
 */
@Getter
@Setter
public class BaseException extends RuntimeException {

    private static final long serialVersionUID = -4831302958147478199L;
    /**
     * 异常数据信息
     */
    private Object data;

    public BaseException() {
        super();
    }

    public BaseException(String msg) {
        super(msg);
    }

    public static String format(String msg, Object... vals) {
        if (StringUtils.isNotBlank(msg)) {
            for (Object val : vals) {
                if (val == null) {
                    val = "";
                }
                msg = msg.replaceFirst("\\{\\}", Matcher.quoteReplacement(val.toString()));
            }
        }
        return msg;
    }

}
